#pragma once

#include <iostream>
#include <string>
#include "Protocol.hpp"
#include "Log.hpp"

class Calulator
{
public:
    Calulator() {}
    Response Exec(Request &req)
    {
        Response ret;
        switch (req._oper)
        {
        case '+':
            /* code */
            ret.SetResult(req._x + req._y);
            break;
        case '-':
            /* code */
            ret.SetResult(req._x - req._y);
            break;
        case '*':
            /* code */
            ret.SetResult(req._x * req._y);
            break;
        case '/':
            /* code */
            if (req._y == 0)
            {
                ret.SetCode(-1);
            }
            else
            {
                ret.SetResult(req._x / req._y);
            }
            break;
        case '%':
            /* code */
            if (req._y == 0)
            {
                ret.SetCode(-2);
            }
            else
            {
                ret.SetResult(req._x % req._y);
            }
            break;
        default:
            LOG(LogLevel::FATAL) << "操作符错误";
            ret.SetCode(-3);//非法操作
            break;
        }
        return ret;
    }
    ~Calulator() {}
};
